package entityJPA;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * The persistent class for the candidate database table.
 * 
 */
@Entity
@Table(name="candidate")
@NamedQueries({
	@NamedQuery(name="Candidate.findAll", query="SELECT c FROM Candidate c"),
	@NamedQuery(name = "Candidate.filterByFirstName", query = "SELECT c FROM Candidate c WHERE c.firstName LIKE :fn"),
	@NamedQuery(name = "Candidate.filterByLastName", query = "SELECT c FROM Candidate c WHERE c.lastName LIKE :ln")})
public class Candidate implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private int idCandidate;

	public Candidate(int idCandidate, String address, String cellNumber,
			byte[] cvUpload, String email, String firstName, String homeNumber,
			String lastName, boolean relocation, Position position,
			List<Interview> interviews) {
		super();
		this.idCandidate = idCandidate;
		this.address = address;
		this.cellNumber = cellNumber;
		this.cvUpload = cvUpload;
		this.email = email;
		this.firstName = firstName;
		this.homeNumber = homeNumber;
		this.lastName = lastName;
		this.relocation = relocation;
		this.position = position;
		this.interviews = interviews;
	}

	@Column(length=45)
	private String address;

	@Column(nullable=false, length=15)
	private String cellNumber;

	@Lob
	@Column(nullable=false)//IMPORTANT!!! nullable trebuie sa fie false
	private byte[] cvUpload;

	@Column(nullable=false, length=45)
	private String email;

	@Column(nullable=false, length=45)
	private String firstName;

	@Column(length=15)
	private String homeNumber;

	@Column(nullable=false, length=45)
	private String lastName;
	
	@Column(nullable=true,name="isAccepted")
	private boolean isAccepted;

	public boolean isAccepted() {
		return isAccepted;
	}

	public void setAccepted(boolean isAccepted) {
		this.isAccepted = isAccepted;
	}

	public List<Candidatecomment> getComments() {
		return comments;
	}

	public void setComments(List<Candidatecomment> comments) {
		this.comments = comments;
	}
	
	private boolean relocation;

	//uni-directional many-to-one association to Position
	@ManyToOne
	@JoinColumn(name="idPosition", nullable=false)//IMPORTANT!!! nullable trebuie sa fie false
	private Position position; 

	//bi-directional many-to-one association to Interview
	@OneToMany(mappedBy="candidate")
	private List<Interview> interviews;
	
	@OneToMany(mappedBy="candidate")
	private List<Candidatecomment> comments;

	public Candidate() {
	}

	public int getIdCandidate() {
		return this.idCandidate;
	}

	public void setIdCandidate(int idCandidate) {
		this.idCandidate = idCandidate;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCellNumber() {
		return this.cellNumber;
	}

	public void setCellNumber(String cellNumber) {
		this.cellNumber = cellNumber;
	}

	public byte[] getCvUpload() {
		return this.cvUpload;
	}

	public void setCvUpload(byte[] cvUpload) {
		this.cvUpload = cvUpload;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getHomeNumber() {
		return this.homeNumber;
	}

	public void setHomeNumber(String homeNumber) {
		this.homeNumber = homeNumber;
	}

	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public boolean getRelocation() {
		return this.relocation;
	}

	public void setRelocation(boolean relocation) {
		this.relocation = relocation;
	}

	public Position getPosition() {
		return this.position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}

	public List<Interview> getInterviews() {
		return this.interviews;
	}

	public void setInterviews(List<Interview> interviews) {
		this.interviews = interviews;
	}

	public Interview addInterview(Interview interview) {
		getInterviews().add(interview);
		interview.setCandidate(this);

		return interview;
	}

	public Interview removeInterview(Interview interview) {
		getInterviews().remove(interview);
		interview.setCandidate(null);

		return interview;
	}
	
	public String toString(){
		return this.idCandidate + " " + this.lastName+" "+this.firstName;
	}

}